package com.dxtan90.doMain;

import com.dxtan90.bean.Action;
import com.dxtan90.config.SysConfig;
import com.dxtan90.judge.PositionJudge;
import com.dxtan90.utils.ConfigUtils;

import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

/**
 * @author: shijunhao
 * @date: 2021/12/1 23:05
 * @description:
 */
public class DoMain {
    public static void main(String[] args) throws InterruptedException {
        PositionJudge positionJudge = new PositionJudge();
        SysConfig config = ConfigUtils.getConfig();
        Action actions = positionJudge.getActions();
        final Action[] action = {actions};
        final int[] times = {1,0};
        Timer timer = new Timer(true);
        TimerTask task = new TimerTask() {
            @Override
            public void run() {
                boolean over = positionJudge.doAction(action[0]);
                if(over){
                    action[0] = action[0].getNext();
                    if(action[0] == null){
                        System.out.println("任务完成次数："+times[0]++);
                        if(config.getInfinite()){
                            action[0] = actions;
                        }else{
                            this.cancel();
                            times[1] = timer.purge();
                        }
                    }
                }
            }
        };
        timer.schedule(task, new Date(System.currentTimeMillis() - 4000), 1000);

        do {
            Thread.sleep(1000L);
        } while (times[1] != 1);

    }
}
